<?php

namespace App\Http\Controllers;

use Carbon\Carbon;
use Illuminate\Http\JsonResponse;

class RestfulBaseController extends Controller
{



    /**
     *
     * 统一json格式返回
     * @param $data
     * @param bool $success
     * @param string $msg
     * @param int $statusCode
     * @return JsonResponse|object
     */
    public function restful($data=null, bool $success=true, string $msg='成功', int $statusCode=200){
        return response()->json([
            'success' => $success,
            'code' => 0,
            'message' => $msg,
            'timestamp' => Carbon::now()->timestamp,
            'data' => $data
        ])->setStatusCode($statusCode);
    }
}
